package com.dx.architectureddd.domain.component.flow;

import com.dx.architectureddd.domain.FlowNodeContext;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Random;

/**
 * 渲染数据——初始化节点执行规则链上下文
 *
 * @author xin.deng
 * @date 2023/10/05
 */
@Slf4j
@LiteflowComponent(id = "RenderedDateCmp", name = "渲染数据")
public class RenderedDateCmp extends NodeComponent {
    @Override
    public void process() {
        FlowNodeContext contextBean = this.getContextBean(FlowNodeContext.class);
        String level = contextBean.getLevel();
        if (StringUtils.isBlank(level)) {
            return;
        }
        int randomInt = new Random().nextInt(10);
        contextBean.setCurLevel((Integer.parseInt(contextBean.getLevel()) + randomInt) + "");
    }
}
